package com.bsoft.gol.hcs.posterUtil;

//字体工具类

import java.awt.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;


public class FontUtil {


    public static final int SIMSUN = 5;
    public static final int SIMSUN1 = 6;


    /**
     * 根据字体类型获取字体
     *
     * @param type
     * @param size
     * @return
     */
    public static Font getFont(String basepath,int type, float size) {
        // 字体路径 TODO
        String path = "";
        switch (type) {
            case SIMSUN:
                path = basepath+ File.separator+"Dengb.ttf";
                break;
            case SIMSUN1:
                path = basepath+ File.separator+"Dengb.ttf";
                break;
        }

        File file = new File(path);
        InputStream inputStream = null;
        try {
            inputStream = new FileInputStream(file);


            Font sPfBoldFont = Font.createFont(Font.TRUETYPE_FONT, inputStream);

            sPfBoldFont = sPfBoldFont.deriveFont(size);
            sPfBoldFont.deriveFont(Font.BOLD);
            return sPfBoldFont;
        } catch (FontFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (inputStream != null) {
                    inputStream.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}

